package wh.删除链表中最大值节点;


/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2022/11/24 15:58
 * @description:删除链表中的最大值节点
 * @version:
 */
public class Solution {
    public static void main(String[] args) {
        ListNode listNode = new ListNode(null,new ListNode(2,new ListNode(5,new ListNode(1,new ListNode(4)))));
        ListNode listNode1 = rmMaxNode(listNode);
        System.out.println(listNode1);
    }

    public static ListNode rmMaxNode(ListNode root) {
        ListNode pre = root,p = root.next,maxPre = root,max = p;
        while (p != null) {
            if (p.val > max.val) {
                max = p;
                maxPre = pre;
            }
            pre = p;
            p = p.next;
        }
        maxPre.next = max.next;
        return root;
    }

}
